package codeassist;

import org.eclipse.ui.console.ConsolePlugin;
import org.eclipse.ui.console.IConsole;
import org.eclipse.ui.console.IConsoleManager;
import org.eclipse.ui.console.MessageConsole;
import org.eclipse.ui.console.MessageConsoleStream;

public class Console {
	public static MessageConsoleStream getConsole(String consoleName) {
		IConsole console = null;

		IConsoleManager manager = ConsolePlugin.getDefault().getConsoleManager();
		IConsole[] consoles = manager.getConsoles();
		for (int i = 0; i < consoles.length; i++) {
			if (consoleName.equals(consoles[i].getName())) {
				console = consoles[i];
				break;
			}
		}

		if (console == null) {
			console = new MessageConsole(consoleName, null);
			manager.addConsoles(new IConsole[] { console });
		}

		manager.showConsoleView(console);

		MessageConsoleStream mcs = ((MessageConsole) console).newMessageStream();

		return mcs;
	}
}
